package com.itheima.afternoon;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class Demo03 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        //method1();
        Class clazz = Class.forName("com.itheima.afternoon.Student");
        Constructor constructor = clazz.getDeclaredConstructor(String.class);
        constructor.setAccessible(true);
        Student student = (Student) constructor.newInstance("1002");
        System.out.println(student);
    }

    private static void method1() throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
        //创建Class类
        Class clazz = Class.forName("com.itheima.afternoon.Student");
        //创建Class类对象
        Constructor constructor = clazz.getConstructor(String.class,String.class);
        Student student = (Student) constructor.newInstance("1001", "张三");
        System.out.println(student);
    }
}
